<?php

namespace app\common\service\asset_manage\service_provider;


use app\common\service\BaseService;
use think\Db;

class HostServiceTypeRelation extends BaseService
{
    /**
     * @name 根据服务商id查询服务商类型
     * @param $serviceId
     * @return array|\PDOStatement|string|\think\Collection
     * @author wx
     * @date time
     */
    public function findType($serviceId)
    {
        return Db::name('host_service_type_relation')->alias('r')
            ->join('host_service_type t','r.type_id = t.id')
            ->where('service_id',$serviceId)
            ->field('type_id,name')
            ->select();
    }

    /**
     * @name 查询id
     * @param $serviceId
     * @return array
     * @author wx
     * @date 2019/10/25 17:31
     */
    public function findTypeId($serviceId)
    {
        return Db::name('host_service_type_relation')->alias('r')
            ->join('host_service_type t','r.type_id = t.id')
            ->where('service_id',$serviceId)
            ->column('type_id');
    }

    /**
     * @name 批量添加
     * @param $addAllData
     * @return int|string
     * @author wx
     * @date 2019/10/24 10:30
     */
    public function addAll($addAllData)
    {
        return Db::name('host_service_type_relation')->insertAll($addAllData);
    }

    /**
     * @name 删除
     * @param $condition
     * @return int
     * @author wx
     * @date 2019/10/24 11:16
     */
    public function del($condition)
    {
        return Db::name('host_service_type_relation')->where($condition)->delete();
    }

    /**
     * @name 查询服务商类型
     * @author wx
     * @date 2020/10/22 14:01
     */
    public function findTypeName($type)
    {
        $typeNameArr = Db::name('host_service_type')->whereIn('id', $type)->column('name');
        $typeName = implode('，', $typeNameArr);

        return $typeName;
    }

}